﻿--[[
   @brief    app tips
   @author   hqzheng
   @version  1.0
   @date     2019-01-7
--]]

app_tips_interval = {
    kDelayReportHover = 2000;
};

app_tips_actions = {
    kActionHover = "hover";
    kActionLight = "show_light";
    kActionUnlight = "show_unlight";
    kActionClick = "click";
};

app_tips = {
    tips_id = 0;
    tips_url = "";

    init = function (parent_id)
        app_tips.tips_id = ui_utility.get_ctrl_id_by_path(parent_id, "CtnAPPTips");
        comm_center.reg_service("SvrShowAPPTips", "app_tips.on_show_tips");
    end;

    inner_log = function (msg, core_msg)
        base_utility.log(string.format("[app_tips] %s", msg), core_msg);
    end;

    show = function (is_show)
        app_tips.inner_log(string.format("[show]is_show:%s", tostring(is_show)));
        ui_utility.set_visible(app_tips.tips_id, is_show);
        if is_show then
            base_utility.add_interval("app_tips.delay_report_apptips_hover", 
                                      app_tips_interval.kDelayReportHover);
        else
            base_utility.remove_interval("app_tips.delay_report_apptips_hover");
        end
    end;

    on_show_tips = function (data)
        if nil == data then
            return;
        end
        app_tips.show(data.is_show);
    end;

    set_background_image = function (url)
        if nil ~= url and "" ~= url then
            url = "ONEIMAGE:client_mainframe\\top_title\\app_tips_bkg.png|"
                .. url .. ";Stretch;0;";            
        else
            url = "ONEIMAGE:client_mainframe\\top_title\\app_tips_bkg.png;Stretch;0";
        end;
        ui_utility.setproperty_by_id(app_tips.tips_id, "Background", url);
    end;

    report_operation = function (action)
        local qos_data = ierd_tgp.tpf_ui.LuaQosDataEx:new();
        local kv_data = {};
        kv_data["action" ] = action;
        qos_data.oc_type    = 1;
        qos_data.qos_kind   = ierd_tgp.adapt_for_imports.qos.Qos_kind.kGameUpdateLackSpace;
        qos_data.str_action = "wegame_app";
        qos_data.str_type   = "frame";
        qos_data.str_json   = base_utility.table_to_json(kv_data);
        base_utility.lua_qos_ex(qos_data);
        qos_data:delete();
    end;

    delay_report_apptips_hover = function()
        base_utility.remove_interval("app_tips.delay_report_apptips_hover");
        app_tips.report_operation(app_tips_actions.kActionHover);
    end;
};
